﻿using System;
using System.Collections.Generic;
using System.Web.Security;

namespace VO.Web.Controllers
{
    public static class MembershipController
    {
        public static List<MembershipUser> GetMembershipUsers()
        {
            List<MembershipUser> list = new List<MembershipUser>();
            foreach (MembershipUser user in Membership.GetAllUsers())
            {
                list.Add(user);
            }
            return list;
        }

        public static void AddUserToAdmin(string key)
        {
            MembershipUser user = Membership.GetUser(new Guid(key));
            Roles.AddUserToRole(user.UserName, "Admins");
        }
        
        public static void RemoveUserFromAdmin(string key)
        {
            MembershipUser user = Membership.GetUser(new Guid(key));
            Roles.RemoveUserFromRole(user.UserName, "Admins");
        }

        public static void UnlockUser(string key)
        {
            MembershipUser user = Membership.GetUser(new Guid(key));
            user.UnlockUser();
        }

        public static bool GetIsAdmin(string key)
        {
            MembershipUser user = Membership.GetUser(new Guid(key));
            return Roles.IsUserInRole(user.UserName, "Admins");
        }

        public static MembershipUser GetUserByKey(string key)
        {
            MembershipUser user = Membership.GetUser(new Guid(key));
            return user;
        }
    }
}
